class code3 {
    //A对半，时间复杂度优化
    public int multiply(int A, int B) {
        int big = A>B?A:B;
        int small = A<B?A:B;
        return sum(big,small);
    }

    public int sum(int big,int small) {
        if(small == 0) return 0;
        if(small == 1) return big;
        int half_small = small>>1;
        int half_sum = sum(big,half_small);

        if(small % 2 == 0) {
            return half_sum *2;
        } else {
            return half_sum*2+big;
        }
    }
}